#include "bgremove.h"
#include <math.h>

bgremove::bgremove(void)
{
	bg = NULL;
	filter_index = BGREMOVE_FILTER;
	learn_speed = 1;
	update_thresh = 50;
}

void bgremove::process(IplImage* src, IplImage* des)
{
	int i,n;
	unsigned char src_pix,bg_pix;
	n = src->height*src->width;
	if(bg == NULL){
		bg = cvCloneImage(src);
	}

	for(i=0;i<n;i++){
		src_pix = src->imageData[i];
		bg_pix = bg->imageData[i];
		/*
		if(bg_pix-src_pix < update_thresh){
			if(src_pix>bg_pix){
				bg->imageData[i] = bg_pix+learn_speed>src_pix?src_pix:(unsigned char)(bg_pix+learn_speed);
			}
		}
		if(bg_pix>src_pix){
			bg->imageData[i] = bg_pix-learn_speed<0?0:(unsigned char)(bg_pix-learn_speed);
		}

		bg_pix = bg->imageData[i];
*/
		des->imageData[i] = src_pix - bg_pix>0?src_pix-bg_pix:0;
	}

}

bgremove::~bgremove(void)
{

}